home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / program / wsc4d21.zip / FIND_PGM.PAS < prev    next >
Pascal/Delphi Source File  |  1997-06-05  |  3KB  |  106 lines

  1. unit Find_pgm;
  2.  
  3. interface
  4.  
  5. uses
  6.   wsc, mio, DisplayUnit,
  7.   SysUtils, WinTypes, WinProcs, Messages,
  8.   Classes, Graphics, Controls,
  9.   Forms, Dialogs, Menus, StdCtrls;
  10.  
  11. type
  12.   TFind = class(TForm)
  13.     MainMenu: TMainMenu;
  14.     FindModem: TMenuItem;
  15.     Exit: TMenuItem;
  16.     Memo: TMemo;
  17.     procedure FormCreate(Sender: TObject);
  18.     procedure ExitClick(Sender: TObject);
  19.     procedure FindModemClick(Sender: TObject);
  20.   private
  21.     { Private declarations }
  22.   public
  23.     { Public declarations }
  24.   end;
  25.  
  26. var
  27.   Find: TFind;
  28.  
  29. implementation
  30.  
  31. {$R *.DFM}
  32.  
  33. procedure TFind.FormCreate(Sender: TObject);
  34. begin
  35.   DisplayLine(Memo,'*** Connect your modem to this computer and turn to ON.');
  36.   DisplayLine(Memo,'*** Select FindModem above to search for your modem.');
  37. end;
  38.  
  39. procedure TFind.ExitClick(Sender: TObject);
  40. begin
  41.   Application.Terminate;
  42. end;
  43.  
  44. procedure TFind.FindModemClick(Sender: TObject);
  45. var
  46.   Port  : Integer;
  47.   Code  : Integer;
  48.   First : Integer;
  49.   Last  : Integer;
  50.   Text  : String;
  51.   Ptr   : PChar;
  52. begin
  53.    First := COM1;
  54.    Last := COM4;
  55.    DisplayLine(Memo,'');
  56.    for Port := First to Last do
  57.      begin
  58.        DisplayString(Memo, Format('*** Examining COM%d: ',[1+Port]));
  59.        Code := SioReset(Port,128,128);
  60.        if Code<0 then DisplayError(Memo,Code)
  61.        else
  62.          begin
  63.            (* turn on DTR or modem won't respond *)
  64.            Code := SioDTR(Port,'S');
  65.            (* modem should raise DSR *)
  66.            if SioDSR(Port) > 0 then
  67.              begin
  68.                DisplayLine(Memo,'Port is found (DSR = 1)');
  69.                GetMem(Ptr,32);
  70.                Text := '!!AT!';
  71.                StrPCopy(Ptr,Text);
  72.                (* send AT *)
  73.                DisplayLine(Memo,'Sending AT');
  74.                mioSendTo(Port,200,Ptr);
  75.                repeat
  76.                  Code := mioDriver(Port);
  77.                  if(Code>=0) then DisplayChar(Memo,Chr(Code))
  78.                until Code = MIO_IDLE;
  79.                (* wait for OK *)
  80.                Text := 'OK';
  81.                StrPCopy(Ptr,Text);
  82.                DisplayLine(Memo,'Waiting for OK . . .');
  83.                mioWaitFor(Port,2000,Ptr);
  84.                repeat
  85.                  Code := mioDriver(Port);
  86.                  if Code>=0 then DisplayChar(Memo,Chr(Code))
  87.                until Code = MIO_IDLE;
  88.                FreeMem(Ptr,32);
  89.                (* did we get OK ? *)
  90.                if mioResult(Port) <> 0 then
  91.                  begin
  92.                    DisplayLine(Memo,'');
  93.                    DisplayLine(Memo,
  94.                      Format('Modem detected on COM%d',[1+Port]));
  95.                    (*break*)
  96.                  end
  97.                else DisplayLine(Memo,'No response.')
  98.              end
  99.            else DisplayLine(Memo,'Port is found (DSR = 0)');
  100.            SioDone(Port);
  101.          end
  102.      end
  103. end;
  104.  
  105. end.
  106.